package com.py.credit.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * 功能描述: 监测到时间类型转换为string
 *
 * @author YaoS
 * @date 19/5/7 10:33
 */
public class DateTrans {

    public static LinkedHashMap<String, Object> tranDate(List<LinkedHashMap<String, Object>> dataInfo, LinkedHashMap<String, Object> dataValue) {
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (LinkedHashMap<String, Object> params : dataInfo) {
            String type = (String) params.get("DATA_TYPE");
            String columnName = (String) params.get("COLUMN_NAME");
            if (type.equals("timestamp") || type.equals("datetime")) {
                if (dataValue.containsKey(columnName) && !columnName.equals("creditTime")) {
                    Object oldValue = dataValue.get(columnName);
                    if (oldValue != null&& oldValue instanceof Date) {
                        dataValue.put(columnName, sdf.format(oldValue));
                    }
                }
            }
        }
        return dataValue;
    }
}
